package com.jpo.common.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.Data;

import java.util.Date;

/**
 * jwt工具类
 */
@Data
//@Component
public class JwtUtils {

    private static final long expire = 604800; // 七天，秒单位
    private static final String secret = "ji8n3439n439n43ld9ne9343fdfer49h";
    private static String header = "Authorization";

//    public static String generateToken(User users) {
//
//        Date nowDate = new Date();
//        Date expireDate = new Date(nowDate.getTime() + 1000 * expire);
//        return Jwts.builder()
//                .signWith(SignatureAlgorithm.HS512, secret)
//                .setHeaderParam("typ", "JWT")
//                .setSubject(users.getName())
//                .setIssuedAt(nowDate)
//                .setExpiration(expireDate)
//                .claim("LOGIN_USER_KEY",null)
//                .compact();
//    }

    public static Claims getClaimsBody(String token) {
        return Jwts.parser()
                .setSigningKey(secret)
                .parseClaimsJws(token)
                .getBody();
    }

    public static boolean isTokenExpired(Claims claims) {
        return claims.getExpiration().before(new Date());
    }

}
